package com.lh1010.s3.service;

import com.lh1010.s3.third.IUserService;
import com.zielsmart.web.basic.exception.UnAuthorizedException;
import com.zielsmart.web.basic.request.TokenUserValidator;
import com.zielsmart.web.basic.tool.JWTTool;
import com.zielsmart.web.basic.vo.JwtPlayLoad;
import com.zielsmart.web.basic.vo.TokenUserInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UserAuthorService implements TokenUserValidator {

    @Resource
    private IUserService userService;

    @Resource
    private JWTTool jwtTool;
    /**
     * 已经有默认实现这里不再处理 如果每个应用有特殊处理在这里处理即可
     *
     * @param --token
     * @return
     */
   /* @Override
    public boolean validator(JwtPlayLoad token) {
        return  true;
    }
*/
    @Override
    public TokenUserInfo userInfo(JwtPlayLoad jwtPlayLoad) throws Exception{
        try {
//            return userService.currentUser(jwtTool.createToken(jwtPlayLoad)).getData();
            return userService.currentUser().getData();
        } catch (Exception e) {
            e.printStackTrace();
            throw new UnAuthorizedException();
        }
    }
}
